package com.le.tester.javaThink.fifth.chapter12_Collections;

import com.le.tester.javaThink.fourth.typeinfo.pets.Pet;
import com.le.tester.javaThink.fourth.typeinfo.pets.Pets;

import java.util.*;

/**
 * createTime：2021/8/31 14:55
 * description：CollectionSequence
 */
public class CollectionSequence extends AbstractCollection<Pet> {

    private List<Pet> pets = Pets.arrayList(8);

    @Override
    public Iterator<Pet> iterator() {
        return new Iterator<Pet>() {
            private int index = 0;

            @Override
            public boolean hasNext() {
                return index < pets.size();
            }

            @Override
            public Pet next() {
                return pets.get(index++);
            }

            @Override
            public void remove() {
                throw new UnsupportedOperationException();
            }
        };
    }

    @Override
    public int size() {
        return pets.size();
    }

    public static void main(String[] args) {
        CollectionSequence c = new CollectionSequence();
        InterfaceVsIterator.display(c);
        InterfaceVsIterator.display(c.iterator());
    }
}
